﻿using Azalea.ORMap;
using NUnit.Framework;

namespace Azalea.Test.ORMap
{
    [TestFixture]
    public class DbInfoTester : Config
    {
        [Test]
        public void TestDbType()
        {
            _dbInfo.DbType(DatabaseTypes.SqlServer);
            Assert.AreEqual(DatabaseTypes.SqlServer, _dbInfo.GetDbType());
        }

        [Test]
        public void TestNameValues()
        {
            _dbInfo
                .DataSource("ms-svr")
                .InitialCatalog("test")
                .UserId("admin")
                .Password("pwd")
                .IntegragedSecurity("true")
                .OtherNameValue("myKey", "myValue");

            Assert.IsTrue(_dbInfo.GetConnectionString().Contains("data source=ms-svr"));
            Assert.IsTrue(_dbInfo.GetConnectionString().Contains("initial catalog=test"));
            Assert.IsTrue(_dbInfo.GetConnectionString().Contains("user id=admin"));
            Assert.IsTrue(_dbInfo.GetConnectionString().Contains("password=pwd"));
            Assert.IsTrue(_dbInfo.GetConnectionString().Contains("integrated security=true"));
            Assert.IsTrue(_dbInfo.GetConnectionString().Contains("mykey=myValue"));
        }

        [Test]
        public void TestStandardOdbcAccess()
        {
            _dbInfo.StandardOdbcAccess(@"c:\test.mdb");

            Assert.AreEqual(DatabaseTypes.Odbc, _dbInfo.GetDbType());
            Assert.IsTrue(_dbInfo.GetConnectionString().Contains("driver={Microsoft Access Driver (*.mdb)}"));
            Assert.IsTrue(_dbInfo.GetConnectionString().Contains(@"dbq=c:\test.mdb"));
        }

        [Test]
        public void TestStandardOdbcExcel()
        {
            _dbInfo.StandardOdbcExcel(@"c:\test.xls");

            Assert.AreEqual(DatabaseTypes.Odbc, _dbInfo.GetDbType());
            Assert.IsTrue(_dbInfo.GetConnectionString().Contains("driver={Microsoft Excel Driver (*.xls)}"));
            Assert.IsTrue(_dbInfo.GetConnectionString().Contains(@"dbq=c:\test.xls"));
        }

        [Test]
        public void TestStandardOdbcSqlite()
        {
            _dbInfo.StandardSqlite(@"c:\test");

            Assert.AreEqual(DatabaseTypes.Sqlite, _dbInfo.GetDbType());
            Assert.IsTrue(_dbInfo.GetConnectionString().Contains(@"data source=c:\test"));
        }

        [Test]
        public void TestStandardOracle()
        {
            _dbInfo.StandardOracle("ms-svr", "admin", "pwd");

            Assert.AreEqual(DatabaseTypes.Oracle, _dbInfo.GetDbType());
            Assert.IsTrue(_dbInfo.GetConnectionString().Contains("data source=ms-svr"));
            Assert.IsTrue(_dbInfo.GetConnectionString().Contains("user id=admin"));
            Assert.IsTrue(_dbInfo.GetConnectionString().Contains("password=pwd"));
        }

        [Test]
        public void TestStandardOracleWithoutDSN()
        {
            _dbInfo.StandardOracleWithoutDSN("localhost", 1521, "mssvr", "admin", "pwd");

            Assert.AreEqual(DatabaseTypes.Oracle, _dbInfo.GetDbType());
            Assert.IsTrue(_dbInfo.GetConnectionString().Contains("data source="));
            Assert.IsTrue(_dbInfo.GetConnectionString().Contains("user id=admin"));
            Assert.IsTrue(_dbInfo.GetConnectionString().Contains("password=pwd"));
        }

        [Test]
        public void TestStandardSqlServer()
        {
            _dbInfo.StandardSqlServer("ms-svr", "test", "admin", "pwd");

            Assert.AreEqual(DatabaseTypes.SqlServer, _dbInfo.GetDbType());
            Assert.IsTrue(_dbInfo.GetConnectionString().Contains("data source=ms-svr"));
            Assert.IsTrue(_dbInfo.GetConnectionString().Contains("initial catalog=test"));
            Assert.IsTrue(_dbInfo.GetConnectionString().Contains("user id=admin"));
            Assert.IsTrue(_dbInfo.GetConnectionString().Contains("password=pwd"));
        }
    }
}